package api

import (
	"blogdemo/gin/errmsg"
	"blogdemo/gin/fileOP"
	"github.com/gin-gonic/gin"
	"net/http"
)

// Upload 上传文件接口, 文件名指定为file
func Upload(c *gin.Context) {
	file, fileHeader, _ := c.Request.FormFile("file")

	fileSize := fileHeader.Size

	url, msgCode := fileOP.UploadFile(file, fileSize)

	c.JSON(http.StatusOK, gin.H{
		"status": msgCode,
		"msg":    errmsg.GetErrMsg(msgCode),
		"url":    url,
	})

}
